class Bullet extends Sprite
{
 
  private Sphere _sphere;
  private float velocity;
  private PVector direction;
  private PVector origin;
  private PVector destination;
  private int lastFrame = 0;
  private final float BULLET_SIZE = 1;
  public final float BULLET_LIFE = 80;
  public int BULLET_SPEED = 7;
  public Terrain terrain;
  private float t = 0;
  private PVector middlePoint1;
  private PVector middlePoint2;
  private boolean arcShot;
  
 public Bullet(PVector location, PVector direction, float damage, Terrain _terrain, boolean arcShot)
 {
   this.location = new PVector(location.x, location.y, location.z);
   this.origin = new PVector(location.x, location.y, location.z);
   this.direction = new PVector(direction.x, direction.y, direction.z);
   this.damage = damage;
   this.spriteSize = BULLET_SIZE;
   this.terrain = _terrain;
   this.arcShot = arcShot;
   health = BULLET_LIFE;
   this.destination = PVector.add(location, PVector.mult(direction, health*BULLET_SPEED));
   createPath();
   _sphere = new Sphere(BULLET_SIZE);
 }
 
 public void draw()
 {
   float x = curvePoint(middlePoint1.x, origin.x, destination.x, middlePoint2.x, t);
   float y = curvePoint(middlePoint1.y, origin.y, destination.y, middlePoint2.y, t);
   float z = curvePoint(middlePoint1.z, origin.z, destination.z, middlePoint2.z, t);
   
//   PVector change = PVector.mult(direction, BULLET_SPEED);
   if (!paused)
   {
     location = new PVector(x, y, z);
     health--;
     if(terrain.update(location.x, location.z).y-4>location.y && health>0)
     {
      health = -20000; 
     }
     t += 1/BULLET_LIFE;
     if (t >= 1)
       health = 0;
   }
   lastFrame++;
   fill(80);
   pushMatrix();
   translate(location.x, location.y, location.z);
   rotateY(lastFrame*PI/25);
   rotateX(lastFrame*PI/25);
   rotateZ(lastFrame*PI/25);
   box(BULLET_SIZE);
   popMatrix();   
 }
 
 private void createPath()
 {
   middlePoint1 = PVector.add(location, PVector.mult(direction, BULLET_LIFE*BULLET_SPEED/4));
   middlePoint2 = PVector.add(location, PVector.mult(direction, BULLET_LIFE*BULLET_SPEED*5/8));
   if (arcShot)
   {
     middlePoint1.y -= 200;
     middlePoint2.y -= 100;
   }
 }
 
 //Override
 public void takeDamage(float damage)
 {
  health = 0; 
 }
 
  
}
